using Xunit;
using static SmartSite.Frame.FrameTypeEnum;

namespace SmartSite.Frame.Test
{
    public class IdentityReqRestoreFrame : RestoreFrame
    {
        protected override FrameTypeEnum Key { get { return IdentityReqFrameType; } }
        public static IdentityReqFrame CreateForTest()
        {
            IdentityReqFrame frame = new IdentityReqFrame();
            frame.FactoryCode.Value = 4;
            frame.MonitorDeviceId.Value = "5678";
            frame.UserName.Value = "ljt";
            frame.PWD.Value = "asdfg";
            frame.CRC.Value = frame.CalculationCRC();
            return frame;
        }

        public IdentityReqRestoreFrame(RestoreFrameCollection restoreFrameDict)
            : base(restoreFrameDict) { }


        protected override BaseFrame GetReferenceFrame() => new IdentityReqFrame();

        protected override void OnRestored(RestoredData restored)
        {
            base.OnRestored(restored);

            Assert.IsType<IdentityReqFrame>(restored.Frame);
            IdentityReqFrame frame = (IdentityReqFrame)restored.Frame;

            Assert.Equal(frame.Buffer, State.BufferClone());
            Assert.Equal(BaseFrameDataEnum.ProtocolVersion, frame.ProtocolVersion.Value);
            Assert.Equal(BaseFrameDataEnum.FactoryCode, frame.FactoryCode.Value);
            Assert.Equal("5678", frame.MonitorDeviceId.Value);
            Assert.Equal("ljt", frame.UserName.Value);
            Assert.Equal("asdfg", frame.PWD.Value);
            Assert.Equal(23319, frame.CRC.Value);

            throw new IdentityReqRestoredFrameException();
        }
    }
}
